package com.yanqu.road.server.cmd.passRoad;

import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.pass.RoadProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.passRoad.PassRoadModule;
import com.yanqu.road.server.gameplayer.module.player.CardModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PASS_ROAD_EVENT_ONE_KEY_DEAL, desc = "新关卡事件一键处理")
public class PassRoadEventOneKeyDealCmd extends AbstractCommand {

	private String reward = "";

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(player.getTitleId() < GameConfig.PASS_ROAD_EVENT_ONE_KEY_DEAL_NEED_TITLE &&
			!player.getModule(CardModule.class).isOneKeyDealPassRoadEvent()){
			ret = GameErrorCode.E_PASS_ROAD_NO_ONE_KEY_DEAL_EVENT;
			return;
		}
		reward = player.getModule(PassRoadModule.class).oneKeyDealEvent();
	}

	@Override
	public void sendData(GamePlayer player) {
		RoadProto.RoadEventOneKeyDealRespMsg.Builder respMsg = RoadProto.RoadEventOneKeyDealRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(0 == ret) {
			respMsg.setReward(reward);
		}
		player.sendPacket(Protocol.U_PASS_ROAD_EVENT_ONE_KEY_DEAL, respMsg);
	}
}
